package cn.geminis.data.jpa.graphql.utils;

import cn.geminis.data.jpa.graphql.types.GraphQLTypes;
import graphql.Scalars;
import graphql.schema.GraphQLOutputType;
import graphql.schema.GraphQLScalarType;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;

/**
 * @author puddi
 */
public class TypeUtils {

    public static GraphQLScalarType getScalarType(Class clazz) {
        if (clazz.equals(int.class) || clazz.equals(Integer.class)) {
            return Scalars.GraphQLInt;
        } else if (clazz.equals(boolean.class) || clazz.equals(Boolean.class)) {
            return Scalars.GraphQLBoolean;
        } else if (clazz.equals(long.class) || clazz.equals(Long.class)) {
            return Scalars.GraphQLLong;
        } else if (clazz.equals(float.class) || clazz.equals(Float.class)) {
            return Scalars.GraphQLFloat;
        } else if (clazz.equals(double.class) || clazz.equals(Double.class)) {
            return Scalars.GraphQLFloat;
        } else if (clazz.equals(short.class) || clazz.equals(Short.class)) {
            return Scalars.GraphQLShort;
        } else if (clazz.equals(String.class)) {
            return Scalars.GraphQLString;
        } else if (clazz.equals(BigInteger.class)) {
            return Scalars.GraphQLBigInteger;
        } else if (clazz.equals(BigDecimal.class)) {
            return Scalars.GraphQLBigDecimal;
        } else if (clazz.isArray() && clazz.getComponentType().equals(byte.class)) {
            return GraphQLTypes.GRAPHQL_BYTE_ARRAY;
        } else if (clazz.equals(LocalDateTime.class)) {
            return GraphQLTypes.GRAPHQL_LOCAL_DATE_TIME;
//        } else if (Date.class.isAssignableFrom(clazz)) {
//            return GraphQLScalars.GRAPHQL_DATE_TYPE;
//        } else if (scalarMap.containsKey(clazz)) {
//            return scalarMap.get(clazz);
        }
        throw new UnsupportedOperationException("Type " + clazz.getName() + " not supported：");
    }
}
